﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EnvironmentManagerSystem.BLL;
using EnvironmentManagerSystem.MODE;
namespace EnvironmentManagerSystem.HuanJing
{
    public partial class HuanJing_TiJiao : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (StfInfo.ReSession()) return;if (!IsPostBack)
            {
                RoleID.Text = Session["roleid"].ToString();
                if (RoleID.Text == "环评单位")
                {
                    Panel1.Visible = false;
                }
                else if (RoleID.Text == "建设单位")
                {
                    Panel1.Visible = false;
                }
                else
                {
                    Panel1.Visible = true;
                }
                AjaxPro.Utility.RegisterTypeForAjax(typeof(EnvironmentManagerSystem.HuanJing.HuanJing_TiJiao));
                BindGv();
            }
        }

        private void BindGv()
        {
            gvList.DataSource = NoticeService.GetNotices();
            gvList.DataBind();
            if (gvList.Rows.Count > 0 && ((Label)gvList.Rows[gvList.Rows.Count - 1].FindControl("Label1")).Text == "是" && XIANGMU.WhetherLeader(Session["UserName"].ToString()))
                btnConfirmation.Visible = true;
            else
                btnConfirmation.Visible = false;
            Notice.Visible = !Session["roleid"].ToString().Contains("建设单位");
        }


        protected void btnConfirmation_Click(object sender, EventArgs e)
        {
            if (NoticeService.UpdateNoticeState(2))
            {               
                Jscript.Alert("操作成功！", this);
                BindGv();
            }
            else
                Jscript.Alert("操作失败！", this);

        }

        protected void btnSay_Click(object sender, EventArgs e)
        {
            NoticeModels nm = new NoticeModels();
            if (txtContent.Text.Trim() == string.Empty)
                Jscript.Alert("请填写通知内容", this);
            else
            {
                if (Session["pjName"].ToString() != null)
                {
                    DevelopprojectbasicinfoDataCollection lst = BLL.XIANGMU.GetByProjectName(Session["pjName"].ToString());
                    nm.project_id = Convert.ToInt32(lst[0].ID);
                    nm.content = txtContent.Text.ToString();
                    nm.date = DateTime.Now.ToString("yyyy-MM-dd");
                    nm.publisher = Session["UserName"].ToString();
                    nm.status = Convert.ToInt32(cbStatus.Checked);
                    if (NoticeService.AddNotice(nm))
                    {
                        Jscript.Alert("添加成功！", this);
                        BindGv();
                    }
                    else
                        Jscript.Alert("添加失败！", this);
                }
            }
        }
    }
}
